<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <script src="/jquery-1.9.1.js"></script>
    <title>用户列表</title>
</head>
<body>
    <table>
      <thead>
          <tr>
              <th>序号</th>
              <th>姓名</th>
              <th>相关操作</th>
          </tr>
      </thead>
      <tbody>
          <% for(let i = 0;i<userinfo.length;i++){ %>
          <tr>
                <td class="num"><%=userinfo[i].id %></td>
                <td><%=userinfo[i].username %></td>
                <td><input type="button" value="删除" class="btn"></td>
          </tr>
          <% } %>
      </tbody>
    </table>
    <script>
        $(function(){
            $(".btn").click(function(){
            let name = $(this).parent().prev().text();
            $.ajax({
                 url:"/del",
                 type:"get",
                 data:{
                     username:name
                 },
                 dataType:"json"
                 ,
                 success:function(data)
                 {
                    alert(data.msg);
                    window.location.href="/users";
                 },
                 error:function(err)
                 {
                  alert(data.msg);
                 }
             })
             })
            })
    </script>
</body>
</html>